<template>
    <fieldset>
        <legend>购物车</legend>
        <ul>
            <li v-for="item in cartData" :key="item.id">
                <b>
                   产品名字：{{item.title}}
                </b>
                -------
                <b>
                    价格：{{item.price}}
                </b>
                -------
                <b>
                    库存：{{item.count}}
                </b>
                -------
                <button @click="delCart(item)" :disabled="item.count===0">返回</button>
            </li>
        </ul>
        <h1>总价:{{total}}</h1>
    </fieldset>
</template>
<script setup>
import { cartCart } from '../../store/cart';
import {useUser} from "../../store/users"
import { storeToRefs } from 'pinia';
let dataOne = cartCart()
let DataOne = useUser()
let {cartData,total} = storeToRefs(dataOne)
let {productData} = storeToRefs(DataOne)
let delCart = (item) => {
    item.count--
    let target = productData.value.find(b=>b.id === item.id)
    if(target){
        target.inventory++
    }
}
</script>